﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Xml;

namespace WindowsGameAula02
{
    static class SaveData
    {
        static XmlDocument xml;
        static XmlNodeList nodes;

        public static void Save(PlayerManager p)
        {
            XmlDocument scene;
            xml.Load("scene.xml");
            string playerTexture;
            string shotTexture;
            Vector2ToXML("root/Player/Position", p.mainPlayer.Position);
            float rotation = 0f;
            Vector2 origin;
            float layerDepth = 0f;
            string effects;
            Vector4 cor;
            Vector2 scale;
            //Rect rect;
            Animation[] a;
            Animation[] sa;

            //XmlNodeList players = scene.SelectNodes("root/Player");

            //foreach (XmlNode ps in players)
            //{
              
            //}

            xml.Save("scene.xml");

        }

        public static void Load(PlayerManager p)
        {
            xml.Load("scene.xml");

            nodes = xml.SelectNodes("root/Player/Position");
            p.mainPlayer.Position = new Vector2(Convert.ToSingle(nodes[0].FirstChild.InnerText),
                Convert.ToSingle(nodes[0].FirstChild.NextSibling.InnerText));
        }

        public static void Vector2ToXML(string path, Vector2 v)
        {
            nodes = xml.SelectNodes(path);
            nodes[0].FirstChild.InnerText = v.X.ToString();
            nodes[0].FirstChild.NextSibling.InnerText = v.Y.ToString();

        }
        public static void Vector4ToXML(string path, Vector4 v)
        {
            nodes = xml.SelectNodes(path);
            XmlNode n = nodes[0].FirstChild;
            n.InnerText = v.X.ToString();
            n = n.NextSibling;
            n.InnerText = v.Y.ToString();
            n = n.NextSibling;
            n.InnerText = v.Z.ToString();
            n = n.NextSibling;
            n.InnerText = v.W.ToString();
        }
        public static void RectToXML(string path, Rectangle r)
        {

            nodes = xml.SelectNodes(path);
            XmlNode n = nodes[0].FirstChild;
            n.InnerText = r.X.ToString();
            n = n.NextSibling;
            n.InnerText = r.Y.ToString();
            n = n.NextSibling;
            n.InnerText = r.Width.ToString();
            n = n.NextSibling;
            n.InnerText = r.Height.ToString();
        }

    }
}
